//
//  YSReadRecordModel.m
//  YSBookRead
//
//  Created by Kyson on 2018/11/6.
//  Copyright © 2018 YangShen. All rights reserved.
//

#import "YSReadRecordModel.h"
#import "YSBookFileManager.h"
#import "YSStorageManager.h"

const NSInteger YSReadLastPageValue = -1;

@implementation YSReadRecordModel

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.bookID forKey:@"bookID"];
    [aCoder encodeInteger:self.readChapter forKey:@"readChapter"];
    [aCoder encodeInteger:self.readPage forKey:@"readPage"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        self.bookID           = [aDecoder decodeObjectForKey:@"bookID"];
        self.readChapter         = [aDecoder decodeIntegerForKey:@"readChapter"];
        self.readPage         = [aDecoder decodeIntegerForKey:@"readPage"];
    }
    return self;
}

+ (instancetype)readRecordWithBookID:(NSString *)bookID {
    YSReadRecordModel *readRecord = [YSStorageManager getReadRecord:bookID];

    /// 不存在
    if (!readRecord) {
        readRecord = [[YSReadRecordModel alloc] init];
        readRecord.bookID = bookID;
    }

    return readRecord;
}



@end
